1 <?php
2 session_start();
3 include("header.php");
4 include("sidebar.php");
5 include("dbconnection.php");
6
7 if(!isset($_SESSION[custid]))
8 {
9 if(!isset($_SESSION[empid]))
10 {
11 header("Location: login.php");
12 }
13 }
14 ?>
15 <script type="text/javascript">
16 function validate()
17 {
18 if(document.form1.bookingid.value=="")
19 {
20 alert("Enter Booking ID");
21 document.form1.bookingid.focus();
22 return false;
23 }
24 if(document.form1.vehname.value=="")
25 {
26 alert("Enter Vehicle Name");
27 document.form1.vehname.focus();
28 return false;
29 }
30 if(document.form1.custname.value=="")
31 {
32 alert("Enter Customer Name");
33 document.form1.custname.focus();
34 return false;
35 }
36 if(document.form1.date.value=="")
37 {
38 alert("Enter the Date");
39 document.form1.date.focus();
40 return false;
41 }
42 if(document.form1.time.value=="")
43 {
44 alert("Enter the Time");
45 document.form1.time.focus();
46 return false;
47 }
48 if(document.form1.comment.value=="")
49 {
50 alert("Enter the Comment");
51 document.form1.comment.focus();
52 return false;
53 }
54 if(document.form1.status.value=="")
55 {
56 alert("Enter Status");
57 document.form1.status.focus();
58 return false;
59 }
60 }
61 </script>
62 <?php
63 //if(isset($_SESSION[custid]))
64 //{
65 // header("Location: account.php");
66 //}
67 $dt= date("Y-m-d");
68 $tm= date("H:m:s");
69
70 if(isset($_POST["submit"]))
71 {
72 $tim = $_POST[hour].":". $_POST[minute].":00";
73
74 $originalDate = $_POST[date];
75 $newDate = date("Y-m-d", strtotime($originalDate));
76
77 $sql ="insert into testdrive(vehicleid,custid,date,time,comments,status) values('$_POST[vahicleid]','$_SESSION[custid]','$newDate','$tim','$_POST[comment]','Pending')";
78
79 if (!mysql_query($sql,$con))
80 {
81 die('Error: ' . mysql_error());
82 }
83 }
84 if(isset($_POST["update"]))
85 {
86 $originalDate = $_POST[date];
87 $newDate = date("Y-m-d", strtotime($originalDate));
88 $tim = $_POST[hour].":". $_POST[minute].":00";
89 $sql ="update testdrive set vehicleid='$_POST[vahicleid]',custid='$_SESSION[custid]',date='$newDate',time='$tim',comments='$_POST[comment]' where bookingid='$_GET[testid]'";
90
91 if (!mysql_query($sql,$con))
92 {
93 die('Error: ' . mysql_error());
94 }
95 if(mysql_affected_rows() == 1)
96 {
97 $resrec = "Test drive record updated succcessfully...";
98 }
99 }
100 ?>
101 <?php
102 if(isset($_GET['testid']))
103 {
104 $result = mysql_query("select * from testdrive where bookingid='$_GET[testid]'");
105 $res=mysql_fetch_array($result);
106 $dt = $res['date'];
107 $tm = $res['time'];
108 }
109 ?>
110
111
112 <div id="main">
113
114 <a name="TemplateInfo"></a>
115 <h1>Test drive</h1>
116
117 <p>
118 <?php
119 if($ctins == 1)
120 {
121 echo "<center><b>Custmer registered Successfully...</b></center><br>";
122 echo "<center><b><a href='login.php'>Click here to Login.</a></b></center>";
123 }
124 else
125 {
126 if(isset($_POST[submit]) || isset($_POST[update]))
127 {
128 echo "<h4>Test drive request sent successfully... </h4>";
129 }
130 else
131 {
132 ?>
133 </p>
134 <p><?php echo $resrec; ?> </p>
135 <form id="form1" name="form1" method="post" action="" onsubmit="return validate()">
136 <table width="522" border="0">
137 <?php
138 if(isset($_GET['testid']))
139 {
140 ?>
141 <tr>
142 <th width="170" height="33" scope="row">Booking ID </th>
143 <td width="247">
144 <label for="vehname"></label>
145 <input name="bookingid" value="<?php echo $res['bookingid']; ?>" readonly="readonly" type="text" id="bookingid" size="35" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;"/>
146 </td>
147 </tr>
148 <?php
149 }
150 ?>
151 <tr>
152 <th height="37" scope="row">Vehicle name
153 <label for="vehname"></label></th>
154 <td>
155 <?php if(isset($_GET['vahicleidnum']))
156 {
157 $res = mysql_query("select vehname from vehiclestore where vehicleid='$_GET[vahicleidnum]'");
158 $rows = mysql_fetch_array($res);
159 ?><input name="vahiclename" type="text" value="<?php echo $rows['vehname']; ?>" /><input type="hidden" name="vahicleid" value="<?php echo $_GET['vahicleidnum']; ?>" />
160 <?php } else { ?>
161 <select name="vahicleid" id="bstatus3">
162 <?php
163 $sql = mysql_query("select vehname,vehicleid from vehiclestore");
164 while($row = mysql_fetch_array($sql))
165 {
166 if($row['vahicleid'] == $res['vehicleid'])
167 {
168 ?>
169 <option value="<?php echo $row['vehicleid']; ?>" selected="selected"><?php echo $row['vehname']; ?></option>
170 <?php }else{ ?>
171 <option value="<?php echo $row['vehicleid']; ?>"><?php echo $row['vehname']; ?></option>
172 <?php
173 }
174 }
175 ?>
176 </select><?php } ?></td>
177 </tr>
178 <!-- <tr>
179 <th height="36" scope="row">Customer name</th>
180 <td><label for="custname"></label>
181 <select name="custid" id="bstatus2">
182 <?php
183 //$sql = mysql_query("select custid,fname from customer");
184 // while($row = mysql_fetch_array($sql))
185 // {
186 // if($row['custid'] == $res['custid'])
187 // {
188 ?>
189 <option value="<?php //echo $row['custid']; ?>" selected="selected"><?php //echo $row['fname']; ?></option>
190 // <?php //}else{ ?>
191 // <option value="<?php //echo $row['custid']; ?>"><?php //echo $row['fname']; ?></option>
192 // <?php
193 // }
194 // }
195 ?>
196 </select></td>
197 </tr>-->
198 <tr>
199 <th height="34" scope="row">Date</th>
200 <td>
201 <?php
202 $dt1 = date("m-d-Y"); ?>
203 <script src="datetimepicker_css.js"></script>
204 <script language="javascript" type="text/javascript" src="datetimepicker.js">
205 </script>
206 <input name="date" type="text" value="<?php echo $dt1; ?>" id="date" size="35" />
207 <a href="javascript:NewCal('date','ddmmmyyyy',false,24)"><img src="cal.gif" width="16" height="16" border="0" alt="Pick a date"></a>
208 </td>
209 </tr>
210 <tr>
211 <th height="40" scope="row">Time</th>
212 <td><label for="time"></label>
213 <select name="hour" id="hour">
214 <option>Hour</option>
215 <option>00</option>
216 <option>01</option>
217 <option>02</option>
218 <option>03</option>
219 <option>04</option>
220 <option>05</option>
221 <option>06</option>
222 <option>07</option>
223 <option>08</option>
224 <option>09</option>
225 <option>10</option>
226 <option>11</option>
227 <option>12</option>
228 <option>13</option>
229 <option>14</option>
230 <option>15</option>
231 <option>16</option>
232 <option>17</option>
233 <option>18</option>
234 <option>19</option>
235 <option>11</option>
236 <option>11</option>
237 <option>11</option>
238 <option>11</option>
239 </select>
240 <select name="minute" id="minute">
241 <option>Minute</option>
242 <option>00</option>
243 <option>01</option>
244 <option>02</option>
245 <option>03</option>
246 <option>04</option>
247 <option>05</option>
248 <option>06</option>
249 <option>07</option>
250 <option>08</option>
251 <option>09</option>
252 <?php
253 for($i=10; $i<=59; $i++)
254 {
255 echo "<option value='$i'>$i</option>";
256 }
257 ?>
258 </select>
259 </td>
260 </tr>
261 <tr>
262 <th height="37" scope="row">Comment</th>
263 <td><textarea name="comment" cols="35" id="comment"><?php echo $res['comments']; ?></textarea></td>
264 </tr>
265 <!-- <tr>
266 <th height="37" scope="row">Status</th>
267 <td><label for="bstatus"></label>
268 <select name="bstatus" id="bstatus">
269 <option value="Pending">Pending</option>
270 <option value="Finished">Finished</option>
271 </select></td>
272 </tr>-->
273 <tr>
274 <th scope="row"> </th>
275 <td><br /><?php if(isset($_GET['testid'])) { ?><input type="submit" name="update" id="submit" value="Update test drive" /><?php } else { ?><input type="submit" name="submit" id="submit" value="Add test drive" /><?php } ?></td>
276 </tr>
277 </table>
278 </form>
279 <?php
280 }
281 }
282 ?>
283 <p> </p>
284 <br />
285
286 </div>
287
288 <!-- wrap ends here -->
289 </div>
290
291 <?php
292 include("footer.php");
293 ?>